<? 
if ($_POST["lang"]!=null)
	$lLangSelected=$_POST["lang"];
else 
	$lLangSelected="eng";
$admin_area=1;
require("adm_header.php"); 
writeCommonAdminTable(LA_ADMIN_MAIL_EDITOR,1);
$tplMail= new tplLoad();

$sFileNameUser="config/language/" . $lLangSelected . "_user.inc";
$sFileNameSystem="language_src/" . $lLangSelected . "_system.inc";


$tplMail->assign("languages",getLangSupported("language_src/"));
$tplMail->assign("lang_selected",$lLangSelected);

if (getParam("submit","")!="")
{
		// Write constants to file
		$sFileContent = "<?php\n";
		$sFileContent.="\$lang_version='$lang_version';\n";
		$sFileContent.="\$lang_date='$lang_date';\n";
		$lConst=getConstantAndValues("$sFileNameUser");
		$lFound=0;
		
		
		
		foreach ($lConst as $key=>$value) 
		{
			$lSkip=0;
			foreach ($_POST as $lKeyPosted => $lValuePosted) 
			{
				if ($lKeyPosted==$key && $lKeyPosted!="submit" && $lKeyPosted!="lang")
				{
					$lConst["$lKeyPosted"]=$lValuePosted;
					$sFileContent .= "define(".var_export($lKeyPosted, true).",".var_export(makeLineBreaksFromCRLF(htmlentities($lValuePosted)), true).");\n";
					$lSkip=1;
				}
				
			}
				
			if (!empty($value) && !$lSkip) {
				 $sFileContent .= "define(".var_export($key, true).",".var_export(makeLineBreaksFromCRLF(htmlentities($value)), true).");\n";
			}
		}
		
		foreach ($_POST as $lKeyPosted => $lValuePosted) 
		{
			if (!$lConst["$lKeyPosted"] && $lKeyPosted!="submit" && $lKeyPosted!="lang")
			{
				$lConst["$lKeyPosted"]=$lValuePosted;
				$sFileContent .= "define(".var_export($lKeyPosted, true).",".var_export(makeLineBreaksFromCRLF(htmlentities($lValuePosted)), true).");\n";
			}
			
		}
		
		
		
		$sFileContent .= "?>";
		
		$rFile = fopen($sFileNameUser, 'w');
		if ($set_demo)
		{
			echo "<b>Demo-mode</b><br>System in demo-mode, no configuration saved!<br>";	
		}
		else 
		{
			
    		fputs($rFile, $sFileContent);
		}
		fclose($rFile);
		chmod($sFileNameUser,octdec($set_chmod));


}



	
$lWelcomeMailTitle=getLangString($lLangSelected,"LA_MAIL_NEWUSER_SUBJECT");
$lWelcomeMailBody=getLangString($lLangSelected,"LA_MAIL_NEWUSER_BODY");
$lValidationTitle=getLangString($lLangSelected,"LA_MAIL_VAL_SUBJECT");
$lValidationMessage=getLangString($lLangSelected,"LA_MAIL_VAL_BODY");
$lApproveAdSubject=getLangString($lLangSelected,"LA_MAIL_APPROVE_AD_SUBJECT");
$lApproveAdBody=getLangString($lLangSelected,"LA_MAIL_APPROVE_AD_BODY");
$lNotifyAdSubject=getLangString($lLangSelected,"LA_MAIL_WATCHNOT_SUBJECT");
$lNotifyAdBody=getLangString($lLangSelected,"LA_MAIL_WATCHNOT_BODY");
$lContactSubject=getLangString($lLangSelected,"LA_MAIL_CONTACT_SUBJECT");
$lContactBody=getLangString($lLangSelected,"LA_MAIL_CONTACT_BODY");
$lTellAFriendSubject=getLangString($lLangSelected,"LA_MAIL_TELLAFRIEND_SUBJECT");
$lTellAFriendBody=getLangString($lLangSelected,"LA_MAIL_TELLAFRIEND_BODY");
$lCommentSubject=getLangString($lLangSelected,"LA_MAIL_COMMENT_SUBJECT");
$lCommentBody=getLangString($lLangSelected,"LA_MAIL_COMMENT_BODY");
$lApproveMemberSubject=getLangString($lLangSelected,"LA_MAIL_APPROVE_MEM_SUBJECT");
$lApproveMemberBody=getLangString($lLangSelected,"LA_MAIL_APPROVE_MEM_BODY");




$lApproveAdSubject=ereg_replace("<br />","\n",$lApproveAdSubject);
$lApproveAdBody=ereg_replace("<br />","\n",$lApproveAdBody);
$lWelcomeMailTitle=ereg_replace("<br />","\n",$lWelcomeMailTitle);
$lWelcomeMailBody=ereg_replace("<br />","\n",$lWelcomeMailBody);
$lValidationTitle=ereg_replace("<br />","\n",$lValidationTitle);
$lValidationMessage=ereg_replace("<br />","\n",$lValidationMessage);
$lNotifyAdSubject=ereg_replace("<br />","\n",$lNotifyAdSubject);
$lNotifyAdBody=ereg_replace("<br />","\n",$lNotifyAdBody);
$lContactSubject=ereg_replace("<br />","\n",$lContactSubject);
$lContactBody=ereg_replace("<br />","\n",$lContactBody);
$lTellAFriendSubject=ereg_replace("<br />","\n",$lTellAFriendSubject);
$lTellAFriendBody=ereg_replace("<br />","\n",$lTellAFriendBody);
$lCommentSubject=ereg_replace("<br />","\n",$lCommentSubject);
$lCommentBody=ereg_replace("<br />","\n",$lCommentBody);
$lApproveMemberSubject=ereg_replace("<br />","\n",$lApproveMemberSubject);
$lApproveMemberBody=ereg_replace("<br />","\n",$lApproveMemberBody);

	
$tplMail->assign("approveadsubject",$lApproveAdSubject);	
$tplMail->assign("approveadbody",$lApproveAdBody);	
$tplMail->assign("welcomemailtitle",$lWelcomeMailTitle);	
$tplMail->assign("welcomemailbody",$lWelcomeMailBody);
$tplMail->assign("validationtitle",$lValidationTitle);
$tplMail->assign("validationmessage",$lValidationMessage);
$tplMail->assign("notifynewsubject",$lNotifyAdSubject);
$tplMail->assign("notifynewbody","".$lNotifyAdBody);
$tplMail->assign("contactsubject",$lContactSubject);
$tplMail->assign("contactbody","".$lContactBody);
$tplMail->assign("tellafriendsubject",$lTellAFriendSubject);
$tplMail->assign("tellafriendbody",$lTellAFriendBody);
$tplMail->assign("commentsubject",$lCommentSubject);
$tplMail->assign("commentbody",$lCommentBody);
$tplMail->assign("approvemembersubject",$lApproveMemberSubject);	
$tplMail->assign("approvememberbody",$lApproveMemberBody);	


$tplMail->display("adm_maileditor.tpl");
writeCommonAdminTable("","");
require("adm_footer.php"); 
?>